<template>
  <view>
    <u-button @click="oneClick" :ripple="true" ripple-bg-color="#a0cfff" :custom-style="customStyle">签到</u-button>
  </view>
</template>

<script>
export default {
  data() {
    return {
      customStyle:{
        color: '#fff',
        fontSize:'40rpx',
        fontWeight:'bolder',
        width: "260rpx",
        height: "260rpx",
        boxShadow: "0px 12rpx 30rpx 0px rgba(25, 137, 250, 0.34)",
        backgroundColor: '#2979ff',
        borderRadius: '50%',
        bottom: '50%',
        left:'30%',
        position:'fixed'
      },
      index: 0,
      id: '',
    };
  },
  onLoad(e){
    this.index = e.index;
    uni.$emit("signNotify",{index:this.index,status:null});
    this.id = e.id;
  },
  methods: {
    oneClick(){
      let data = {
        signUserId: this.$store.getters.id,
        signTaskId: this.id
      }
      this.$u.api.saveSignIn(data).then(res => {
        if (res.code === 200) {
          uni.$emit("signNotify",{index:this.index,status:1});
          this.$u.toast('签到成功');
          setTimeout(() => {
            uni.switchTab({
              url: '/pages/notify/notify',
              fail: () => {
                this.$u.toast('跳转页面失败！');
              }
            })
          },1000)
        }else {
          this.$u.toast('签到失败！')
        }
      })
    }
  }
}
</script>

<style lang="scss">

</style>
